package cn.mw.cmdb.enums;

import cn.mw.cmdb.param.MwKeyValueParam;
import com.google.common.base.Strings;

import java.util.ArrayList;
import java.util.List;

public enum InstanceDetailTabEnum {
    detail("detail", "资产详情", "", false,""),
    history("history", "变更历史", "", false,""),
    //虚拟化、紫光云视图
    virtualDetail("virtualDetail", "虚拟化视图", "", true,"97143051729764352,134075107944431616"),
    daoBoxDetail("daoBoxDetail", "刀箱视图", "", true,"97210952583217152"),
    topo("topo", "实例拓扑", "", false,""),
    monitorDetail("monitorDetail", "资产监控", "enableMonitor", true,""),
    logDetail("logDetail", "日志详情", "enableLogManage", true,""),
    flowDetail("flowDetail", "流量监控", "enableFlow", true,"");
    private String type;
    private String name;
    private String code;
    private boolean isDefault;
    private String modelId;

    InstanceDetailTabEnum(String type, String name, String code, boolean isDefault,String modelId) {
        this.type = type;
        this.name = name;
        this.code = code;
        this.isDefault = isDefault;
        this.modelId = modelId;
    }



    public String getType() {
        return type;
    }

    public void setType(String type) {
        this.type = type;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public boolean isDefault() {
        return isDefault;
    }

    public void setDefault(boolean aDefault) {
        isDefault = aDefault;
    }

    public String getModelId() {
        return modelId;
    }

    public void setModelId(String modelId) {
        this.modelId = modelId;
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public static MwKeyValueParam getDetailTabType(String code) {
        for (InstanceDetailTabEnum r : InstanceDetailTabEnum.values()) {
            if (r.getCode().equals(code)) {
                MwKeyValueParam keyValueParam = new MwKeyValueParam();
                keyValueParam.setName(r.getName());
                keyValueParam.setValue(r.getType());
                return keyValueParam;
            }
        }
        return null;
    }

    public static MwKeyValueParam getDetailTabByModelId(String modelId) {
        for (InstanceDetailTabEnum r : InstanceDetailTabEnum.values()) {
            if (!Strings.isNullOrEmpty(r.getModelId()) && r.getModelId().contains(modelId)) {
                MwKeyValueParam keyValueParam = new MwKeyValueParam();
                keyValueParam.setName(r.getName());
                keyValueParam.setValue(r.getType());
                return keyValueParam;
            }
        }
        return null;
    }

    public static MwKeyValueParam getDefaultTabInfo() {
        MwKeyValueParam keyValueParam = new MwKeyValueParam();
        keyValueParam.setName(detail.getName());
        keyValueParam.setValue(detail.getType());
        return keyValueParam;
    }

    /**
     * 获取默认显示的tab信息
     *
     * @return
     */
    public static List<MwKeyValueParam> getDefaultManageTab() {
        List<MwKeyValueParam> list = new ArrayList<>();
        for (InstanceDetailTabEnum r : InstanceDetailTabEnum.values()) {
            MwKeyValueParam keyValueParam = new MwKeyValueParam();
            if (!r.isDefault) {
                keyValueParam.setName(r.getName());
                keyValueParam.setValue(r.getType());
                list.add(keyValueParam);
            }
        }
        return list;
    }
}
